﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ADV_Evaluator.Data
{
	[Serializable]
	class SaveSprite
	{
		public string[] texture = null;
		public string[] key = null;
		public float[] location_X = null;
		public float[] location_Y = null;
		public float[] rect_left = null;
		public float[] rect_right = null;
		public float[] rect_top = null;
		public float[] rect_bottom = null;
		public float[] width = null;
		public float[] height = null;
		public double[] alpha = null;
		public bool[] visible = null;
		public int[] fadeinDuration = null;
		public int[] fadeoutDuration = null;
		public int[] fadeinCount = null;
		public int[] fadeoutCount = null;

		public void InitSaveSprite(SpriteList sprite)
		{
			texture = new string[sprite.Count];
			key = new string[sprite.Count];
			location_X = new float[sprite.Count];
			location_Y = new float[sprite.Count];
			rect_left = new float[sprite.Count];
			rect_right = new float[sprite.Count];
			rect_top = new float[sprite.Count];
			rect_bottom = new float[sprite.Count];
			width = new float[sprite.Count];
			height = new float[sprite.Count];
			alpha = new double[sprite.Count];
			visible = new bool[sprite.Count];
			fadeinDuration = new int[sprite.Count];
			fadeoutDuration = new int[sprite.Count];
			fadeinCount = new int[sprite.Count];
			fadeoutCount = new int[sprite.Count];

			for (int i = 0; i < sprite.Count; i++)
			{
				texture[i] = sprite[i].TextureName;
				key[i] = sprite.keys[i];
				visible[i] = sprite[i].Visible;
				location_X[i] = sprite[i].Location.X;
				location_Y[i] = sprite[i].Location.Y;
				if (sprite[i].SrcRect != null)
				{
					rect_left[i] = sprite[i].SrcRect.Left;
					rect_right[i] = sprite[i].SrcRect.Right;
					rect_top[i] = sprite[i].SrcRect.Top;
					rect_bottom[i] = sprite[i].SrcRect.Bottom;
				}
				if (sprite[i].DestSize != null)
				{
					width[i] = sprite[i].DestSize.Cx;
					height[i] = sprite[i].DestSize.Cy;
				}
				alpha[i] = sprite[i].Alpha;
				fadeinDuration[i] = sprite[i].FadeinDuration;
				fadeoutDuration[i] = sprite[i].FadeoutDuration;
				fadeinCount[i] = sprite[i].FadeinCount;
				fadeoutCount[i] = sprite[i].FadeoutCount;
			}
		}

		public void InitSaveSprite(MySprite sprite)
		{
			texture = new string[1];
			key = new string[1];
			location_X = new float[1];
			location_Y = new float[1];
			rect_left = new float[1];
			rect_right = new float[1];
			rect_top = new float[1];
			rect_bottom = new float[1];
			width = new float[1];
			height = new float[1];
			alpha = new double[1];
			visible = new bool[1];
			fadeinDuration = new int[1];
			fadeoutDuration = new int[1];
			fadeinCount = new int[1];
			fadeoutCount = new int[1];

			texture[0] = sprite.TextureName;
			visible[0] = sprite.Visible;
			location_X[0] = sprite.Location.X;
			location_Y[0] = sprite.Location.Y;
			if (sprite.SrcRect != null)
			{
				rect_left[0] = sprite.SrcRect.Left;
				rect_right[0] = sprite.SrcRect.Right;
				rect_top[0] = sprite.SrcRect.Top;
				rect_bottom[0] = sprite.SrcRect.Bottom;
			}
			if (sprite.DestSize != null)
			{
				width[0] = sprite.DestSize.Cx;
				height[0] = sprite.DestSize.Cy;
			}
			alpha[0] = sprite.Alpha;
			fadeinDuration[0] = sprite.FadeinDuration;
			fadeoutDuration[0] = sprite.FadeoutDuration;
			fadeinCount[0] = sprite.FadeinCount;
			fadeoutCount[0] = sprite.FadeoutCount;
		}

		public void LoadSprite(ref SpriteList sprite)
		{
			for (int i=0;i<texture.Length;i++)
			{
				MySprite sp = new MySprite();
				LoadSprite(ref sp, i);
				sprite.Add(key[i], sp);
			}
		}

		public void LoadSprite(ref MySprite sprite)
		{
			if (texture[0] != null && texture[0] != string.Empty)
			{
				sprite.Load(texture[0]);
				sprite.Visible = visible[0];
				sprite.X = location_X[0];
				sprite.Y = location_Y[0];
				sprite.SrcRect.Left = rect_left[0];
				sprite.SrcRect.Right = rect_right[0];
				sprite.SrcRect.Top = rect_top[0];
				sprite.SrcRect.Bottom = rect_bottom[0];
				sprite.DestSize.Cx = width[0];
				sprite.DestSize.Cy = height[0];
				sprite.DblAlpha = alpha[0];
				sprite.FadeinDuration = fadeinDuration[0];
				sprite.FadeoutDuration = fadeoutDuration[0];
				sprite.FadeinCount = fadeinCount[0];
				sprite.FadeoutCount = fadeoutCount[0];
			}
		}

		public void LoadSprite(ref MySprite sprite, int i)
		{
			if (texture[i] != null && texture[i] != string.Empty)
			{
				sprite.Load(texture[i]);
				sprite.Visible = visible[i];
				sprite.X = location_X[i];
				sprite.Y = location_Y[i];
				sprite.SrcRect.Left = rect_left[i];
				sprite.SrcRect.Right = rect_right[i];
				sprite.SrcRect.Top = rect_top[i];
				sprite.SrcRect.Bottom = rect_bottom[i];
				sprite.DestSize.Cx = width[i];
				sprite.DestSize.Cy = height[i];
				sprite.DblAlpha = alpha[i];
				sprite.FadeinDuration = fadeinDuration[i];
				sprite.FadeoutDuration = fadeoutDuration[i];
				sprite.FadeinCount = fadeinCount[i];
				sprite.FadeoutCount = fadeoutCount[i];
			}
		}
	}
}
